package com.xxy.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxy.context.BaseContext;
import com.xxy.entity.Order;
import com.xxy.entity.dto.OrderQueryDTO;
import com.xxy.entity.vo.OrderVO;
import com.xxy.entity.vo.ProductVO;
import com.xxy.mapper.OrderMapper;
import com.xxy.result.PageResult;
import com.xxy.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<OrderVO> queryByFilter(OrderQueryDTO orderQueryDTO) {
        orderQueryDTO.setUserId(BaseContext.getCurrentId());
        return orderMapper.queryByFilter(orderQueryDTO);
    }

    @Override
    public PageResult query(OrderQueryDTO orderQueryDTO) {
        Page<OrderVO> page = new Page<>(orderQueryDTO.getCurrent(), orderQueryDTO.getSize());
        IPage<OrderVO> resultPage = orderMapper.query(page, orderQueryDTO);
        List<OrderVO> records = resultPage.getRecords();
        long total = resultPage.getTotal();
        return new PageResult(total, records);
    }
}
